package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pojo.SysResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import sun.security.pkcs11.wrapper.Constants;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lyj
 * @since 2023-02-16
 */
public interface SysResourceMapper extends BaseMapper<SysResource> {

    @Select("select distinct sre.*\n" +
            "from sys_user su \n" +
            "left join sys_user_role sur on su.id=sur.user_id\n" +
            "left join sys_role_resource srr on sur.role_id=srr.role_id\n" +
            "left join sys_resource sre on srr.resource_id=sre.id ${ew.customSqlSegment}")
    List<SysResource> queryByUserId(@Param("ew") QueryWrapper<SysResource> wrapper);

    @Select("select distinct sre.*\n" +
            "from sys_resource sre,\n" +
            "sys_role_resource srr,\n" +
            "sys_role sr\n" +
            "where sre.id = srr.resource_id\n" +
            "and srr.role_id=sr.id\n" +
            "and sre.del_flag=0\n" +
            "and srr.del_flag=0\n" +
            "and sr.id=#{roleId}")
    List<SysResource> queryByRoleId(Long roleId);
}
